import {
  get,
  post,
  put,
  del,
} from "./base_service"


/**
 * 招聘相关接口
 *
 * allen  2021-08-24
 */

/**
 * 查询所有招聘列表
 */
const queryAllInviteList = (page, pageSize, words, salary, experience, education) => {
  return new Promise((resolve, reject) => {
    get("/job", {
      page: page,
      pageSize: pageSize,
      words,
      salary,
      experience,
      education
    }).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}




/**
 * 创建一条招聘信息
 * @param {*}} data 
 */
const createInviteInfo = (data) => {
  return new Promise((resolve, reject) => {
    post("/job", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新一条招聘信息
 * @param {*}} data 
 */
const updateInviteInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/job", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取一条招聘详情
 * @param {*} id 
 */
const queryInviteDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/job/detail", { id: id }).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 上下架一条招聘信息
 * @param {*} id 
 */
const pushOrDownInvite = (id) => {
  return new Promise((resolve, reject) => {
    get("/job/push", { id: id }).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取用户自己发布的招聘列表
 */
const queryMyInviteList = (examineStatus) => {
  return new Promise((resolve, reject) => {
    get("/job/query?examineStatus=" + examineStatus).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 删除一条招聘信息
 * @param {*} id 
 */
const cancleOneInvite = (id) => {
  return new Promise((resolve, reject) => {
    del("/job/" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询招募二维码
 * @param {*} id 
 */
const queryInviteQrCode = (id) => {
  return new Promise((resolve, reject) => {
    get("/job/create/qr/code?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 审核招募信息
 * @param {*} id 
 * @param {*} isPass 
 * @param {*} remark 
 */
const checkInvitedAction = (id, isPass, remark) => {
  return new Promise((resolve, reject) => {
    get("/job/examine?id=" + id + "&isPass=" + isPass + "&remark=" + remark).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}












module.exports = {
  queryAllInviteList,
  createInviteInfo,
  updateInviteInfo,
  queryInviteDetail,
  pushOrDownInvite,
  queryMyInviteList,
  cancleOneInvite,
  queryInviteQrCode,
  checkInvitedAction
}
